package com.tao.listen.direct;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


/**
 * @ClassName DirectConsumer
 * @Author HETAO
 * @Date 2020/5/5 10:04
 */
@Component
public class DirectConsumer {
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue,
            exchange = @Exchange(value = "directs", type = ExchangeTypes.DIRECT),
            key = {"user.add"}
    ))
    public void test(String msg, Channel channel) {
        System.out.println("user.add==>" + msg);
        System.out.println(channel.getChannelNumber());
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue,
            exchange = @Exchange(value = "directs", type = ExchangeTypes.DIRECT),
            key = {"user.delete"}
    ))
    public void test2(String msg, Channel channel) {
        System.out.println("user.delete" + msg);
        System.out.println(channel.getChannelNumber());
    }
}
